//
//  MYTabBar.swift
//  swift2.0项目开始
//
//  Created by 龚昕炜 on 16/7/28.
//  Copyright © 2016年 龚昕炜. All rights reserved.
//

import UIKit

class MYTabBar: UITabBar {

    override init(frame: CGRect) {

        super.init(frame: frame)
        
        setUpUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        let width = bounds.width * 0.2
        let height = bounds.height
        
        var index = 0
        
        for subview in subviews {
        
            if subview.isKindOfClass(NSClassFromString("UITabBarButton")!) {
            
                subview.frame = CGRectMake(CGFloat(index) * width, 0, width, height)
                
                index++
                
                if index == 2 {index++}
            }
        }
        
        compose2Button.frame = CGRectMake(2 * width, 0, width, height)
    }
    
    func click() {
    
    }
    
    private func setUpUI() {
        addSubview(compose2Button)
    }
    
    lazy var compose2Button: UIButton = {
    
        let button = UIButton()
        
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: .Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: .Highlighted)
        
        button.addTarget(self, action: "click", forControlEvents: .TouchUpInside)
        
        return button
    }()

}
